/**
	This file is part of Fighting Field.

	Fighting Field is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Fighting Field is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Fighting Field.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef FF_GAME_H
#define FF_GAME_H

#include "Prerequisites.h"

#include "StateMachine.h"

namespace FF
{
	class GuiManager;
	class InputManager;
}

namespace FF
{
	class Game
		: public Ogre::Singleton<Game>
		, public StateMachine
		, public Ogre::FrameListener
	{
	public:
		Game();
		~Game();

		void Go();

		Ogre::Root* GetRoot();
		
		void CreateRenderWindow(unsigned int width, unsigned int height, bool fullScreen, const Ogre::NameValuePairList* miscParams = NULL);
		Ogre::RenderWindow* GetRenderWindow();

		InputManager* GetInputManager();

		GuiManager* GetGuiManager();

		static Game& Get();
        static Game* GetPtr();

	protected:
		bool frameStarted(const Ogre::FrameEvent& evt);
		bool frameRenderingQueued(const Ogre::FrameEvent& evt);
		bool frameEnded(const Ogre::FrameEvent& evt);

		void InitResources();
		void ReleaseResources();

		void SetupView();

	protected:
		Ogre::Root* mRoot;
		Ogre::RenderWindow* mWindow;
		InputManager* mInputManager;
		GuiManager* mGuiManager;

		Ogre::Real mPrevStep;
		static const Ogre::Real msStepDt;
	};

	inline Ogre::Root* Game::GetRoot()
	{
		return mRoot;
	}

	inline Ogre::RenderWindow* Game::GetRenderWindow()
	{
		return mWindow;
	}

	inline InputManager* Game::GetInputManager()
	{
		return mInputManager;
	}

	inline GuiManager* Game::GetGuiManager()
	{
		return mGuiManager;
	}

	static Game* GetGame()
	{
		return Game::GetPtr();
	}
}

#endif